﻿using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.DBCore.Redis.CMultiplexer.Interface
{
    /// <summary>
    /// RedisBase类，是redis操作的基类，继承自IDisposable接口，主要用于释放内存
    /// </summary>
    public abstract class CMultiplexerBase : IDisposable
    {
        public ConnectionMultiplexer conClient { get; private set; }
        public IDatabase dbClient { get; private set; }

        private bool _disposed = false;

        public CMultiplexerBase(int conIndex,int dbIndex)
        {
            conClient = CMultiplexerManager.CreateManager(conIndex);
            dbClient=CMultiplexerManager.GetRedisManager.GetClient(conIndex,dbIndex);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    conClient.Dispose();
                    conClient = null;
                }
            }
            this._disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
